package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/7 15:48
 */
public class HWBJ72 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();
        List<List<Integer>> list = new ArrayList<>();

        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c != ']') {
                stack.push(c);
            } if (c == ']') {
                List<Integer> l = new ArrayList<>();
                while (!stack.empty()) {
                    char ch = stack.pop();
                    if (Character.isDigit(ch)) {
                        l.add(Integer.parseInt(String.valueOf(ch)));
                    } else if (ch == '[') {
                        if (!l.isEmpty()) {
                            Collections.reverse(l);
                            list.add(l);
                        }
                        break;
                    }
                }
            }
        }
        List<Integer> maxList = new ArrayList<>();
        for (int i = 0; i < list.get(0).size(); i++) {
            int max = Integer.MIN_VALUE;
            for (int j = 0; j < list.size(); j++) {
                max = Math.max(max,list.get(j).get(i));
            }
            maxList.add(max);
        }
        maxList.sort(Comparator.naturalOrder());
        System.out.println(maxList.get(0));
    }
}
